<template>
  <div class="afterInvestDel-page">
    <pubChunk>
      <div slot="title" class="flex-v-center">
        <span class="title">{{ strategy_dels.strategyName }}</span>
        <el-tooltip
          v-if="strategy_dels.mark"
          popper-class="tit-tip"
          effect="light"
          :visible-arrow="false"
          :open-delay="500"
          :content="strategy_dels.mark"
          placement="right"
        >
          <i class="el-icon-document fontdoc"></i>
        </el-tooltip>
        <!-- <el-button
          size="small"
          :type="dateFreq == 1 ? 'primary' : ''"
          :disabled="defaultDateFreq > 1"
          @click="dateFreq = 1"
          >日频</el-button
        >
        <el-button -->
        <el-button-group
          v-if="investType == 1 && strategy_dels.strategyName"
          style="margin-left: 14px"
        >
          <el-button
            size="small"
            :type="titleDataType ? '' : 'primary'"
            @click="cutDataHandle(0)"
            >期货账号拟合数据</el-button
          >
          <el-button
            size="small"
            :type="titleDataType ? 'primary' : ''"
            @click="cutDataHandle(1)"
            >子账号拟合数据</el-button
          >
        </el-button-group>
      </div>
      <div slot="subtitle">
        <div class="sub-title flex">
          <div class="tagBox">
            <span
              class="tag"
              v-for="(item, i) in strategy_dels.tagList"
              :key="i"
            >
              {{ item }}
            </span>
          </div>
        </div>
      </div>
      <div slot="headLeft" style="width: 361px">
        <el-button v-show="strategy_dels.haveSubAccount" size="small" type="primary" @click="goPerformance" style="height: 33px;">绩效分析</el-button>
        <el-button size="small" type="primary" @click="goContrast">
          <i class="iconfont icon-haeder icon-jia"></i>
          去对比
        </el-button>
        <el-button
          size="small"
          icon="el-icon-edit"
          @click="addOrUpdateHandle(strategy_dels.strategyId)"
        >
          编辑
        </el-button>
        <el-button size="small" @click="refreshPage">
          <i class="iconfont icon-shuaxin"></i>
          刷新
        </el-button>
      </div>
      <div class="head3">
        <div class="head-content flex">
          <div class="left">
            <el-row :gutter="12">
              <el-col :span="8">
                <div class="fromLine">
                  <div class="label label-line2">
                    <p>单位净值：</p>
                    <p class="fs12 tip">
                      {{
                        strategy_dels.detial &&
                        strategy_dels.detial.networthTime | parseTime
                      }}
                    </p>
                  </div>
                  <div class="fromLine-content fzBig">
                    {{
                      strategy_dels.detial && strategy_dels.detial.unitNetworth
                    }}
                  </div>
                </div>
              </el-col>
              <el-col :span="7">
                <div class="fromLine">
                  <div class="label label-line2">
                    <p>今年以来收益率：</p>
                    <p class="fs12 tip">
                      截止至{{
                        strategy_dels.detial &&
                        strategy_dels.detial.networthTime | parseTime
                      }}
                    </p>
                  </div>
                  <div class="fromLine-content fzBig">
                    <span
                      v-if="
                        strategy_dels.extend &&
                        strategy_dels.extend[strategyId][0].incomeRate
                      "
                      :class="
                        strategy_dels.extend[strategyId][0].incomeRate > 0
                          ? 'positiveFc1'
                          : 'negativeFc1'
                      "
                    >
                      {{
                        strategy_dels.extend[strategyId][0].incomeRate
                          | toFixed2
                      }}%
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
              <el-col :span="9">
                <div class="fromLine">
                  <div
                    class="label label-line2"
                    style="width: 138.69px; text-align: right"
                  >
                    <p>成立以来收益率：</p>
                    <p class="fs12 tip tof">
                      成立日期：{{ strategy_dels.makeTime | parseTime }}
                    </p>
                  </div>
                  <div class="fromLine-content fzBig">
                    <span
                      v-if="
                        strategy_dels.extend &&
                        strategy_dels.extend[strategyId][7].incomeRate
                      "
                      :class="
                        strategy_dels.extend[strategyId][7].incomeRate > 0
                          ? 'positiveFc1'
                          : 'negativeFc1'
                      "
                    >
                      {{
                        strategy_dels.extend[strategyId][7].incomeRate
                          | toFixed2
                      }}%
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
            </el-row>
            <el-row :gutter="12" style="margin-top: 16px">
              <el-col :span="8">
                <div class="fromLine">
                  <div class="label" style="width: 78.69px; text-align: right">
                    累计净值：
                  </div>
                  <div class="fromLine-content fw">
                    {{
                      strategy_dels.detial &&
                      strategy_dels.detial.cumulativeNetworth
                    }}
                  </div>
                </div>
              </el-col>
              <el-col :span="7">
                <div class="fromLine">
                  <div class="label" style="width: 112px; text-align: right">
                    近3月收益率：
                  </div>
                  <div class="fromLine-content fw">
                    <span
                      v-if="
                        strategy_dels.extend &&
                        strategy_dels.extend[strategyId][2].incomeRate
                      "
                      :class="
                        strategy_dels.extend[strategyId][2].incomeRate > 0
                          ? 'positiveFc1'
                          : 'negativeFc1'
                      "
                    >
                      {{
                        strategy_dels.extend[strategyId][2].incomeRate
                          | toFixed2
                      }}%
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
              <el-col :span="9">
                <div class="fromLine">
                  <div class="label" style="width: 138.69px; text-align: right">
                    年化收益率：
                  </div>
                  <div class="fromLine-content fw">
                    <span
                      v-if="strategy_dels.riskIndicatorsBean"
                      :class="
                        strategy_dels.riskIndicatorsBean.annualizedIncomeRate >
                        0
                          ? 'positiveFc1'
                          : 'negativeFc1'
                      "
                    >
                      {{
                        strategy_dels.riskIndicatorsBean.annualizedIncomeRate
                          | toFixed2
                      }}%
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
            </el-row>
            <el-row :gutter="12">
              <el-col :span="8">
                <div class="fromLine">
                  <div class="label" style="width: 78.69px; text-align: right">
                    复权净值：
                  </div>
                  <div class="fromLine-content fw">
                    {{
                      strategy_dels.detial &&
                      strategy_dels.detial.reinstatementNetworth
                    }}
                  </div>
                </div>
              </el-col>
              <el-col :span="7">
                <div class="fromLine">
                  <div class="label" style="width: 112px; text-align: right">
                    近6月收益率：
                  </div>
                  <div class="fromLine-content fw">
                    <span
                      v-if="
                        strategy_dels.extend &&
                        strategy_dels.extend[strategyId][3].incomeRate
                      "
                      :class="
                        strategy_dels.extend[strategyId][3].incomeRate > 0
                          ? 'positiveFc1'
                          : 'negativeFc1'
                      "
                    >
                      {{
                        strategy_dels.extend[strategyId][3].incomeRate
                          | toFixed2
                      }}%
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
              <el-col :span="9">
                <div class="fromLine">
                  <div class="label" style="width: 138.69px; text-align: right">
                    夏普比率：
                  </div>
                  <div class="fromLine-content fw">
                    <span v-if="strategy_dels.riskIndicatorsBean">
                      {{
                        strategy_dels.riskIndicatorsBean.sharpeRate | toFixed2
                      }}
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
            </el-row>
            <el-row :gutter="12">
              <el-col :span="8"><div style="height: 22px"></div></el-col>
              <el-col :span="7">
                <div class="fromLine">
                  <div class="label" style="width: 112px; text-align: right">
                    近1年收益率：
                  </div>
                  <div class="fromLine-content fw">
                    <span
                      v-if="
                        strategy_dels.extend &&
                        strategy_dels.extend[strategyId][4].incomeRate
                      "
                      :class="
                        strategy_dels.extend[strategyId][4].incomeRate > 0
                          ? 'positiveFc1'
                          : 'negativeFc1'
                      "
                    >
                      {{
                        strategy_dels.extend[strategyId][4].incomeRate
                          | toFixed2
                      }}%
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
              <el-col :span="9">
                <div class="fromLine">
                  <div class="label" style="width: 138.69px; text-align: right">
                    最大回撤：
                  </div>
                  <div class="fromLine-content fw">
                    <span v-if="strategy_dels.riskIndicatorsBean">
                      {{ strategy_dels.riskIndicatorsBean.maximumDrawdownRate }}
                    </span>
                    <span v-else>/</span>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>
          <div class="right">
            <div class="fromLine">
              <div class="label label-line2">
                <p>资产金额：</p>
                <p class="fs12 tip tof">单位：万元</p>
              </div>
              <div class="fromLine-content fzBig">
                {{ strategy_dels.initMoney }}
              </div>
            </div>
            <div class="fromLine">
              <div class="label">开始日期：</div>
              <div class="fromLine-content">
                {{ strategy_dels.makeTime | parseTime }}
              </div>
            </div>
          </div>
        </div>
      </div>
    </pubChunk>
    <allStrategyOpen
      v-if="allStrategyVisible"
      title="添加实盘"
      type="radio"
      ref="allStrategy"
      :userId="userId"
      :disabled="[`${'Z' + id}`]"
      :noDblclick="true"
      @selctInvestName="selctInvestNameHandle"
    ></allStrategyOpen>
    <addOrUpdateDialog
      ref="addOrUpdateOpen"
      @closeOpen="refreshPage"
      type="update"
      :addOrUpdateView.sync="addOrUpdateView"
      :row="listRow"
    ></addOrUpdateDialog>
  </div>
</template>
<script>
import addOrUpdateDialog from "../dialog";
import { randomNum } from "@/utils/pro";
import allStrategyOpen from "@/views/other/allStrategyOpen.vue";
import pubChunk from "@/components/investComn/pubChunk.vue";
import { getHeadDetail } from "@/api/combManage";
import mixin from "./mixins";
import { findStrategyDetialHead, strategyByid } from "@/api/policyManage";
// import { parseTime, deepClone } from '@/utils'
import { getToken } from '@/utils/auth'

export default {
  mixins: [mixin],
  components: {
    pubChunk,
    allStrategyOpen,
    addOrUpdateDialog,
  },
  data() {
    return {
      listLoading: false,
      allStrategyVisible: false,
      listRow: { investId: "" },
      addOrUpdateView: false,
    };
  },
  props: {
    strategy_dels_parent: {
      type: Object || Array,
    },
    titleDataType: {
      type: Number,
      default: 0,
    },
    chart_date_parent: {
      type: Array | Object,
    },
  },
  mounted() {
    this.getInfo();
  },
  methods: {
    goPerformance() {
      const token = getToken()
      let accountList = this.strategy_dels.subAccounts.map(item => {
        return {
          investAccount: item.investAccount,
          investInitialEquity: item.investInitialEquity
        }
      })
      let ip = process.env.NODE_ENV === "production" ? 'http://invest.hzyotoy.com/jx' : 'http://192.168.12.49:62'
      // const url = `http://192.168.12.82:9000/#/home/index?open=1&accountType=1&token=${token}&userId=${this.userId}&name=${this.strategy_dels.strategyName}&accountList=${JSON.stringify(accountList)}`
      const url = `${ip}/#/home/index?open=1&accountType=1&token=${token}&userId=${this.userId}&name=${this.strategy_dels.strategyName}&accountList=${JSON.stringify(accountList)}&date=${JSON.stringify(this.chart_date_parent)}`
      window.open(url)
    },
    cutDataHandle(i) {
      this.$emit("cutDataHandle", i);
    },
    selctInvestNameHandle(row) {
      this.$emit("update:realquery", row);
    },
    async getInfo() {
      if (this.titleDataType) {
        await getHeadDetail({
          compositionId: this.compositionId,
        }).then((res) => {
          this.strategy_dels = {
            ...res.body,
            strategyId: this.strategyId,
            strategyName: res.body.compositionName,
            makeTime: res.body.netWorthTime,
            extend: {
              [this.strategyId]: res.body.compositionNetWorthExtendBeans,
            },
            detial: {
              networthTime: res.body.netWorthEndTime,
              unitNetworth: res.body.compositionNetWorth,
              cumulativeNetworth: res.body.compositionNetWorth,
              reinstatementNetworth: res.body.compositionNetWorth,
            },
            netWorthDetialBean: { networthTime: res.body.netWorthEndTime },
          };
        });
        const values = await Promise.all([
          findStrategyDetialHead({ strategyId: this.strategyId }),
          strategyByid({
            strategyId: this.strategyId,
            userId: this.userId,
          }),
        ]);
        console.log("投资详情-header", values[0]);
        console.log("投资详情-content", values[1]);
        const _strategy_dels = {
          ...this.strategy_dels,
          ...values[0].body,
          ...values[1].body.strategyInfoVo,
          riskIndicatorsBean: values[1].body.riskIndicatorsBean,
          netWorthDetialBean: values[1].body.netWorthDetialBean,
        };
        this.$emit("update:strategy_dels_parent", _strategy_dels);
      } else {
        const values = await Promise.all([
          findStrategyDetialHead({ strategyId: this.strategyId }),
          strategyByid({
            strategyId: this.strategyId,
            userId: this.userId,
          }),
        ]);
        console.log("投资详情-header", values[0]);
        console.log("投资详情-content", values[1]);
        this.strategy_dels = {
          ...this.strategy_dels,
          ...values[0].body,
          ...values[1].body.strategyInfoVo,
          riskIndicatorsBean: values[1].body.riskIndicatorsBean,
          netWorthDetialBean: values[1].body.netWorthDetialBean,
        };
        this.$emit("update:strategy_dels_parent", this.strategy_dels);
      }
    },
    goContrast() {
      const res_list = [
        {
          id: this.strategyId,
          name: this.strategy_dels.strategyName,
          type: 1,
        },
      ];
      const id = randomNum(6);
      this.$router.push({
        path: `/policyManage/contrast/${id}`,
        query: {
          list: JSON.stringify(res_list),
          one: 1,
        },
      });
    },
    addOrUpdateHandle(id) {
      this.listRow.investId = id;
      this.addOrUpdateView = true;
    },
    refreshPage() {
      const view = this.$route;
      this.$store.dispatch("tagsView/delCachedView", view).then(() => {
        const { fullPath } = view;
        this.$nextTick(() => {
          this.$router.replace({
            path: "/redirect" + fullPath,
          });
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.afterInvestDel-page {
  .title {
    font-size: 26px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #262626;
    display: inline-block;
    margin-right: 10px;
  }
  .icon-jia {
    font-size: 12px;
    margin-right: 6px;
  }
  .icon-shuaxin {
    font-size: 14px;
    margin-right: 6px;
  }
}
</style>
